import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Scanner;

public class text {
    public static void main(String[] args) throws DocumentException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入您要输入的类");
        String s = sc.next();
        SAXReader saxReader = new SAXReader();
        Document read = saxReader.read(text.class.getClassLoader().getResourceAsStream("bean.xml"));
        Element rootElement = read.getRootElement();
        List<Element> elements = rootElement.elements("servlet");
        Element servlet_element = null;
        for (Element element : elements) {
            String url = element.attributeValue("url");
            if (url.equals(s)) {
              /*  Class<?> aClass = Class.forName(url);
                Constructor<?> constructor = aClass.getConstructor();
                Object o = constructor.newInstance();
                Method method = aClass.getMethod("method");
                method.invoke(o);
                break;*/
                servlet_element = element;
                break;
            }
        }
        if (servlet_element == null) {
            System.out.println("对不起您输入的类不存在");
        } else {
            String className = servlet_element.attributeValue("class");
            Class<?> aClass = Class.forName(className);
            Constructor<?> constructor = aClass.getConstructor();
            Object o = constructor.newInstance();
            Method method = aClass.getMethod("method");
            method.invoke(o);
        }
    }
}
